package com.kele.oplog.controller;

import com.kele.common.model.response.PageResult;
import com.kele.common.model.response.Result;
import com.kele.common.model.response.ResultObject;
import com.kele.model.oplog.BrowseLog;
import com.kele.oplog.service.BrowseLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("oplog")
//@CrossOrigin
public class BrowseLogController {

    @Autowired
    private BrowseLogService browseLogService;

    /**
     * @param pageNo
     * @param pageSize
     * @param searchMap
    {
    "goodsName":"华为",
    "priceMin":"1000",
    "priceMax":"3000",
    "brand":"华为",
    "category":"手机",
    "sortField":"price",
    "sortOrder":"ASC"
    }
     * @return
     */
    //@RequestMapping(value = "search/{pageNo}/{pageSize}",method = RequestMethod.POST)
    @PostMapping("search/{pageNo}/{pageSize}")
    public PageResult<BrowseLog> search(@PathVariable Integer pageNo,
                                        @PathVariable Integer pageSize,
                                        @RequestBody Map searchMap){

        return browseLogService.search(pageNo,pageSize,searchMap);
    }

    @GetMapping("{id}")//
    public ResultObject<BrowseLog> get(@PathVariable String id){
        return browseLogService.findById(id);
    }

    @PostMapping
    public Result insert(@RequestBody BrowseLog browseLog){
        browseLog.setBrowseTime(new Date());
        return browseLogService.insert(browseLog);
    }

    @PutMapping("{id}")//
    public Result update(@PathVariable String id,@RequestBody BrowseLog browseLog){
        return browseLogService.update(id,browseLog);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable String id){
        return browseLogService.delete(id);
    }

    @GetMapping("delete/{id}")
    public Result delete1(@PathVariable String id){
        return browseLogService.delete(id);
    }
}
